#ifndef RENDERER_H
#define RENDERER_H

#include "../common/common.h"

#include "rd_surface.h"

//地图
typedef struct {
	char name[MAX_OSPATH];

	int w, h;

	//奇数
	//偶数
	// |- 4倍数
	// |   |- 8倍数
	// |   `- 非8倍数
	// `- 非4倍数

	int * tile;		//地图数据 tile[]

	int trows, tcols;	//tile rows, tile cols

	int tw, th;			//tile width, tile height

	int tm, ts;			//tile margin, tile spacing

	surface_t * sprite;	//自定义地面信息
} map_t;

//模型
typedef struct {
	char name[MAX_OSPATH];

	int num;

	int w, h;

	int step[3];			//每帧间隔步长
	int frames[3];			//总帧数
	surface_t * sprite[3];	//WALK | RUN | ATTACK
} model_t;
#define MAX_MODELS 1024

//render部分全局变量
typedef struct {
	surface_t *	screen;
	bool		fullscreen;

	map_t		map;

	int			model_count;
	model_t		models[MAX_MODELS];

	rect_t		camera;
	bool		camera_locked;

	surface_t *	cursor_img;
	surface_t *	sight_mask;
	surface_t *	shadow;

	surface_t *	debug;
} rd_globals_t;


void init_renderer(void);
void release_renderer(void);

void rd_show_all(void);
void rd_toggle_fullscreen(void);

//只能存在一张地图
void		rd_load_map(const char * mapname);
void		rd_show_map(void);

model_t *	rd_load_model(const char * modelname);
rect_t *	rd_model_clip(model_t * m, int direction, int frame);
void		rd_free_models(void);	//一场游戏结束时

bool		rd_rect_collision(rect_t * A, rect_t * B);

extern rd_globals_t rd;

#endif /* end of include guard: RENDERER_H */
